#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include<string>
#include<cmath>
#include<typeinfo>
//using namespace std;
//template<typename TY>
//class SeqStack
//{
//private:
//	Ty* m_date;
//	size_t m_ccapacity;
//	int m_top;
//	static const int ininsize = 16;
//public:
//	SeqStack(size_t sz = initsize)
//		:m_top(-1),
//		m_capacity(sz)
//	{
//		m_date = (Ty*)malloc(sizeof(Ty) * m_capacity);
//		if (nullptr == m_data)exit(EXIT_FAILURE);
//	}
//};
//~SeqStack()
//{
//	size_t getCapa() const { return m_capacity; }
//	size_t getSize() const { return m_top+1; }
//	bool is_empty()  const { return GetSizeof() == 0; }
//	bool is_full()  const { return GetSizeof() == 0; }
//
//
//
//	
//}




#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<typeinfo>
#include<stdio.h>
#include<vector>
#include<string.h>
using namespace std;

template<typename Ty>  // template<class Ty>
class SeqStack
{
private:
	Ty* m_data;
	size_t m_capacity;
	int m_top;
	static const int initsize = 16;

	bool IncSize()
	{
		int total = m_capacity * 2;
		Ty* newdata = (Ty*)malloc(sizeof(Ty) * total);
		if (nullptr == newdata) return false;
		for (int i = 0; i <= m_top; ++i)
		{
			new(&newdata[i]) Ty(m_data[i]);
		}
		for (int i = 0; i <= m_top; ++i)
		{
			(&m_data[i])->~Ty();
		}
		m_data = newdata;
		m_capacity = total;
		return true;
	}
public:
	SeqStack(size_t sz = initsize)
		:m_top(-1), // m_top(0)
		m_capacity(sz)
	{
		m_data = (Ty*)malloc(sizeof(Ty) * m_capacity);
		if (nullptr == m_data) exit(EXIT_FAILURE);
	}
	~SeqStack()
	{
		clear();
		free(m_data);
		m_data = nullptr;
		m_capacity = 0;
	}
	void clear()
	{
		for (int i = 0; i <= m_top; ++i)
		{
			(&m_data[i])->~Ty();
		}
		m_top = -1;
	}
	size_t getCapa() const
	{
		return m_capacity;
	}
	size_t getSize() const
	{
		return m_top + 1;
	}
	bool is_empty() const
	{
		return getSize() == 0;
	}
	bool is_full() const
	{
		return getSize() == getCapa();
	}
	bool push(const Ty& val)
	{
		if (is_full() && IncSize())
		{
			return false;
		}
		//m_data[++top] = val;  // cc
		new(&m_data[++m_top]) Ty(val);
		return true;
	}

	bool getTop(Ty& val)
	{
		if (is_empty()) return false;
		val = m_data[m_top];
		return true;
	}
	bool pop(Ty& val)
	{
		if (is_empty()) return false;
		val = m_data[m_top];
		(&m_data[m_top])->~Ty();
		m_top -= 1;
		return true;
	}
};
int main()
{
	SeqStack<int> ist;
	for (int i = 0; i < 100; ++i)
	{
		ist.push(i);
	}
	int val;
	while (!ist.is_empty())
	{
		ist.pop(val);
		cout << val << endl;
	}
	return 0;
}